package com.xsomnus.open.base.handler;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/4/30 0030 14:35
 * 当你发现自己的才华撑不起野心时，就请安静下来学习吧
 */
public abstract class AbstractMessageHandler<T, R> implements MessageHandler<T, R> {

    @Override
    public abstract void check(T t);

    @Override
    public abstract void before();

    @Override
    public R handle(T t) {
        this.check(t);
        this.before();
        try {
            R ret = doHandle(t);
            this.after(t, ret);
            return ret;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    abstract R doHandle(T t) throws MessageHandlerException;

    @Override
    public abstract void after(T t, R r);
}
